<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
//文件大小的人性化显示
function size_format($size=0,$num=0){
    $unit=['B','KB','MB','GB','TB'];
    $i=0;
    while ($size>1024){
        $size/=1024;//$size=$size/1024
        $i++;
    }
    return round($size,$num) .$unit[$i];
}
// 生成导航url
function makeurl($id){
    $cate=db('cate')->field('type,id,link')->where('id',$id)->find();
    $url="";
    $type=$cate['type'];
    switch($type){
        case 1:
        $url=url('index/lists/index',['id'=>$id]);
        break;
        case 2:
        $url=url('index/page/index',['id'=>$id]);
        break;
        case 3:
        $url=$cate['link'];
        break;
        default:
            $url=url('index/index/index');
            break;
    }
    return $url;
}
//字符串截取
function subtext($text, $length)

{

if(mb_strlen($text, 'utf8') > $length)

return mb_substr($text,0,$length,'utf8').' …';

return $text;

}